1 00:00:00,780 --> 00:00:05,580 Today I'm going to introduce a wave loop so that things can happen periodically. 2 00:00:05,580 --> 00:00:10,800 And also I want to introduce module scripts, which are scripts that can be called from other scripts. 3 00:00:10,800 --> 00:00:15,080 So we're going to use them as a code library, which is really, really useful. 4 00:00:15,090 --> 00:00:19,650 So let's go over here to server script service, open it up, see what we got in there. 5 00:00:19,650 --> 00:00:22,260 Well, we do have this spanner in here. 6 00:00:22,260 --> 00:00:23,850 That's a regular script. 7 00:00:23,850 --> 00:00:29,610 I'm going to hit the plus sign and I'm going to add a module script, write, module script. 8 00:00:29,610 --> 00:00:33,540 Make sure you get that right, because a regular script is not going to work if you're trying it. 9 00:00:33,930 --> 00:00:37,860 All right, this module script, I'm going to call session utils. 10 00:00:39,570 --> 00:00:41,850 It's going to be a library of functions. 11 00:00:41,850 --> 00:00:42,290 Whoops. 12 00:00:42,900 --> 00:00:45,090 But I'm going to call from another script now. 13 00:00:45,090 --> 00:00:46,140 Session utils. 14 00:00:46,260 --> 00:00:48,120 Let me make this bigger so you can see it. 15 00:00:49,970 --> 00:00:57,860 Is going to have a table inside it when we require our session utils in another script or include it. 16 00:00:57,860 --> 00:01:02,630 If you're more familiar with that terminology, we're going to get a table returned. 17 00:01:02,630 --> 00:01:05,540 It's going to have our functions stored in the table. 18 00:01:05,540 --> 00:01:06,650 Pretty cool. 19 00:01:06,680 --> 00:01:14,150 I'm going to call this table utils and if you change the name here, you have to change the name down 20 00:01:14,150 --> 00:01:14,750 here. 21 00:01:14,750 --> 00:01:18,980 It does not have to match this one obviously because I have session utils. 22 00:01:18,980 --> 00:01:19,550 Right. 23 00:01:20,000 --> 00:01:26,810 And let's go and make a function that we're going to store in this utils table that we can use someplace 24 00:01:26,810 --> 00:01:27,380 else. 25 00:01:27,380 --> 00:01:38,090 So I'm going to say function not local because it's not local to my script, utils, colon, start wav 26 00:01:39,140 --> 00:01:48,470 and then just go put a little print statement in here, print wav starting if I could spell it right. 27 00:01:48,470 --> 00:01:49,880 There we go. 28 00:01:49,880 --> 00:01:51,650 It's pretty simple to start off. 29 00:01:51,650 --> 00:01:57,890 Now let's go to server script service on a close Z spanner so it gets out of the way, but in server 30 00:01:57,890 --> 00:01:59,570 script servers are going to hit the plus. 31 00:01:59,600 --> 00:02:04,730 Now I'm going to get a regular script right, or a server script, we call it. 32 00:02:04,730 --> 00:02:07,880 It just says script, but it runs on the server. 33 00:02:08,030 --> 00:02:09,980 I'm going to call this wave loop. 34 00:02:12,720 --> 00:02:13,050 All right. 35 00:02:13,050 --> 00:02:18,270 And in wave loop, I want to require my session utils. 36 00:02:18,270 --> 00:02:20,730 I want to import it or include it. 37 00:02:20,760 --> 00:02:23,100 Whatever programming language you come from. 38 00:02:23,100 --> 00:02:24,570 Or maybe not at all. 39 00:02:24,570 --> 00:02:25,020 Right. 40 00:02:25,020 --> 00:02:28,080 So they use require in node.js. 41 00:02:28,080 --> 00:02:30,870 So you like that if you want to do Node.js. 42 00:02:31,050 --> 00:02:31,410 All right. 43 00:02:31,410 --> 00:02:35,010 So I'm going to require and I need to find it. 44 00:02:35,010 --> 00:02:38,760 So we have this top level game object in there. 45 00:02:38,760 --> 00:02:43,080 We have server script service, that's this right here. 46 00:02:43,080 --> 00:02:48,780 And then I could do this dot session, Utils Walla, I got my utils. 47 00:02:48,780 --> 00:02:52,770 This is going to be the table that's going to have all my functions in there. 48 00:02:52,770 --> 00:03:02,430 So let me do a little loop here while true do and then I'll do a little weight statement. 49 00:03:02,430 --> 00:03:10,020 You don't want to crash your machine and we'll go utils colon start wav. 50 00:03:10,020 --> 00:03:11,460 Let's see what we got. 51 00:03:11,460 --> 00:03:19,140 We should see this print statement firing once a second, so we'll hit the play button. 52 00:03:19,140 --> 00:03:22,620 Let's go to The View so we can take a look at our output window. 53 00:03:23,720 --> 00:03:24,710 And there we go. 54 00:03:24,710 --> 00:03:29,120 Waves started so you could see that it's printing over and over and over again. 55 00:03:30,060 --> 00:03:30,710 Oh, look at that. 56 00:03:30,720 --> 00:03:31,860 We had our eruption. 57 00:03:31,860 --> 00:03:33,480 We should put that in the wave. 58 00:03:33,510 --> 00:03:34,590 That would be pretty cool.